<?php 
$fullname = "";
if(isset($user) && !empty($user)){
	$fullname = $user[0]->first_name .($user[0]->middle_name != ''?' '.$user[0]->middle_name:'') . ($user[0]->last_name != ''?' '.$user[0]->last_name:'');
}

?>

<div class="clear_both"></div>
<div class="main_container">
<div class="sub_tabs">
<ul class="idTabs"> 
  <li><a href="#personal_data">Personal Data</a></li> 
  <li><a href="#dependents">Dependents</a></li> 
  <li><a href="#education">Education</a></li> 
  <li><a href="#employment">Employment</a></li>
  <li><a href="#salary">Salary</a></li>
  <li><a href="#contributions">Contributions/Deductions</a></li>
</ul>
<div class="file201_userlabel"><?php echo $fullname;?></div>
</div>
<div style='display:"none"; height:1px; overflow:hidden'>
<?php echo form_open_multipart('user/uploadPicture', array('target'=>'hidden_frame'));?>
<input type="file" name="userfile" size="20" />
<?php echo form_hidden("old_photo",isset($user[0])?$user[0]->photo:'');?>
<?php echo form_hidden("user_id",$user_id);?>
<br /><br />
<input type="submit" value="upload" id="upload_button" />
</form>
</div>

<?php echo form_open('user/file201', array('id'=>'file201_form'));?>
<div class="file201" id="personal_data">
<div class="clear_both"></div>
<fieldset>
<legend>PERSONAL DATA</legend>

<div class="fieldset_container_2">
	<div class="column_1">
		<ul>
		<li> <label for="first_name">First Name</label>
		<input type="text" name="first_name" id="first_name" size="30" value="<? echo isset($user[0]->first_name)? $user[0]->first_name: "";?>"/></li>
		<li> <label for="last_name">Last Name</label>
		<input type="text" name="last_name" id="last_name" size="30" value="<? echo isset($user[0]->last_name)? $user[0]->last_name: "";?>"/></li>
		
		<li> <label for="middle_name">Middle Name</label>
		<input type="text" name="middle_name" id="middle_name" size="30" value="<? echo isset($user[0]->middle_name)? $user[0]->middle_name: "";?>"/></li>
		
		<li> <label for="birth_date">Date of Birth</label>
		<?php 
			if(isset($user[0]->birth_date)){
				list($yr, $mon, $date) = explode("-", $user[0]->birth_date);
				//$bod = "$mon"
			}
		
		?>
		<input type="text" name="birth_date" id="birth_date" readonly="readonly" size="30" value="<? echo isset($user[0]->birth_date)? $user[0]->birth_date: "";?>" /></li>
	
		<li> <label for="gender">Gender</label>
		<?php 
		$options = array('' =>'-- Select --',
                  'Male'  => 'Male',
                  'Female'    => 'Female');

		echo form_dropdown('gender', $options , isset($user[0]->gender)? $user[0]->gender: "");
		
		?>
		</li>
		
		<li> <label for="present_address">Present Address</label>
		<textarea rows="5" cols="30" name="present_address"><? echo isset($user[0]->present_address)? $user[0]->present_address: "";?></textarea></li>

	
		<li> <label for="home_address">Home Address</label>
		<textarea rows="5" cols="30" name="home_address"><? echo isset($user[0]->home_address)? $user[0]->home_address: "";?></textarea></li>
		
		<li> <label for="home_phone">Home Phone</label>
		<input type="text" name="home_phone" id="home_phone" size="30" value="<? echo isset($user[0]->home_phone)? $user[0]->home_phone: "";?>" /> </li>
		
		<li> <label for="mobile_phone">Mobile Phone</label>
		<input type="text" name="mobile_phone" id="mobile_phone" size="30" value="<? echo isset($user[0]->mobile_phone)? $user[0]->mobile_phone: "";?>" /> </li>
		<?php if(isset($user[0]) && $user[0]->status == 'Married'):?>
		<li> <label for="spouse_last_name">Spouse Last Name</label>
		<input type="text" name="spouse_last_name" id="spouse_last_name"size="30" value="<? echo isset($user[0]->spouse_last_name)? $user[0]->spouse_last_name: "";?>" /> </li>
		
		<li> <label for="spouse_first_name">Spouse First Name</label>
		<input type="text" name="spouse_first_name" id="spouse_first_name"size="30" value="<? echo isset($user[0]->spouse_first_name)? $user[0]->spouse_first_name: "";?>" /> </li>
		
		<li> <label for="spouse_middle_name">Spouse Middle Name</label>
		<input type="text" name="spouse_middle_name" id="spouse_middle_name"size="30" value="<? echo isset($user[0]->spouse_middle_name)? $user[0]->spouse_middle_name: "";?>" /> </li>
		<?php endif;?>
		<li> <label for="notify_person">Notify Person</label>
		<input type="text" name="notify_person" id="notify_person" size="30" value="<? echo isset($user[0]->notify_person)? $user[0]->notify_person: "";?>" /> </li>
		
		<li> <label for="notify_phone">Notify Phone</label>
		<input type="text" name="notify_phone" id="notify_phone" size="30" value="<? echo isset($user[0]->notify_phone)? $user[0]->notify_phone: "";?>"/> </li>
		
		<li> <label for="notify_mobile_phone">Notify Mobile Phone</label>
		<input type="text" name="notify_mobile_phone" id="notify_mobile_phone" size="30" value="<? echo isset($user[0]->notify_mobile_phone)? $user[0]->notify_mobile_phone: "";?>"/> </li>
		<li><label for="submit">&nbsp;</label>
		<?php echo form_hidden("user_id",$user_id);?>
		<input type="submit" name="submit" id="file201_submit" value="Save"></li>
		<ul>
	</div>
	<div class="column_2">
		<div class="preloader_container" id="image_preloader">
			<div class="preloader_image" style="margin:auto;"></div>
		</div>
		<img class="member_photo" src="<?php echo base_url()?><?php echo (isset($user[0]) && $user[0]->photo !='')?'uploads/'.$user[0]->photo:'images/members/default.jpg';?>" />
		<br>
		<a href="javascript:;" class="small_link" id="upload_link">Upload new photo</a> 
		<br><br>
		<ul>
		<li> <label for="first_name">TIN</label>
		<span class="native_bold"><input type="text" name="tin" id="tin" size="30" value="<? echo isset($user[0]->tin)? $user[0]->tin: "";?>" /></span></li>
		<li> <label for="last_name">SSS</label>
		<span class="native_bold"><input type="text" name="sss" id="sss" size="30" value="<? echo isset($user[0]->sss)? $user[0]->sss: "";?>" /></span></li>
		
		<li> <label for="middle_name">HDMF/Pag-ibig</label>
		<span class="native_bold"><input type="text" name="pag_ibig" id="pag_ibig" size="30" value="<? echo isset($user[0]->pag_ibig)? $user[0]->pag_ibig: "";?>" /></span></li>
		
		<li> <label for="middle_name">PhilHealth</label>
		<span class="native_bold">
		<input type="text" name="philhealth" id="philhealth" size="30" value="<? echo isset($user[0]->philhealth)? $user[0]->philhealth: "";?>" />
		</span></li>
		
		<li> <label for="birth_date">Blood Type</label>
		<span class="native_bold">
		<input type="text" name="blood_type" id="blood_type" size="30" value="<? echo isset($user[0]->blood_type)? $user[0]->blood_type: "";?>" />
		</span></li>
	
		<ul>
	</div>
</div>
<?php echo form_close();?>
</fieldset>
</div>
</br />
<?php echo form_open('user/education');?>
<div class="file201" id="education">
<fieldset>
<legend>EDUCATIONAL ATTAINMENT</legend>

<table border="1" cellspacing="0" cellpadding="5" id="education_table" class="display">
	<thead>
		<tr>
			<th>School Name</th>
			<th>Course</th>
			<th>Date Started</th>
			<th>Date Ended</th>
			<th>Level</th>
			<th>Action</th>
		</tr>
		<?php foreach($education as $edu):?>
		<?php endforeach;?>
	</thead>
	<?php foreach($education as $edu){
	?>
	<tr id="tr_education_<?php echo $edu->id;?>">
		<td><span name="school_name"><?php echo isset($edu->school_name)?$edu->school_name:'--';?></span></td>
		<td><span name="course_name"><?php echo isset($edu->course_name)?$edu->course_name:'--';?></span></td>
		<td><span name="date_start"><?php echo isset($edu->date_start)?$edu->date_start:'--';?></span></td>
		<td><span name="date_end"><?php echo isset($edu->date_end)?$edu->date_end:'--';?></span></td>
		<td><span name="type"><?php echo isset($edu->type)?$edu->type:'--';?></span></td>
		<td>
			<a href="javascript:;" onClick="editData('<?php echo $edu->id?>','education')" >Edit</a> | <a href="javascript:;" onClick="deleteData('<?php echo $edu->id?>','education')">Delete</a>
		</td>
	</tr>
	<?php } ?>
	</table>

<p><a href="#" class="add_entry" action="education">Add educational attainment</a></p>
</fieldset>
</div>
<?php echo form_close();?>
</br />
<?php echo form_open('user/dependents');?>
<div class="file201" id="dependents">
<fieldset>
<legend>DEPENDENTS</legend>

	<table border="1" cellspacing="0" cellpadding="5" id="dependents_table" class="display">
	<thead>
				<tr>
					<th>Name</th>
					<th>Date of Birth</th>
					<th>Gender</th>
					<th>Type</th>
					<th>Action</th>
				</tr>
			</thead>
	<?php foreach($dependents as $dependent){
	
		$fullname = $dependent->first_name;
		if(isset($dependent->middle_name))$fullname .= ' ' . $dependent->middle_name;
		if(isset($dependent->last_name))$fullname .= ' ' . $dependent->last_name;
	?>
	<tr id="tr_dependent_<?php echo $dependent->id;?>">
		<td><span name="dependent_full_name"><?php echo $fullname?></span></td>
		<td><span name="dependent_birth_date"><?php echo isset($dependent->birth_date)?$dependent->birth_date:'';?></span></td>
		<td><span name="dependent_gender">
			<?php
				if(isset($dependent->gender)) echo $dependent->gender;
			?>
			</span>
		</td>
		<td>
			<span name="dependent_type">
			<?php
				if(isset($dependent->type)) echo $dependent->type;
			?>
			</span>
		</td>
		<td>
			<a href="javascript:;" onClick="editData('<?php echo $dependent->id?>','dependent')" >Edit</a> | <a href="javascript:;" onClick="deleteData('<?php echo $dependent->id?>','dependent')">Delete</a>
		</td>
	</tr>
	<?php } ?>
	</table>


	
	<?php echo form_hidden("user_id",$user_id);?>
<p><a href="#" class="add_entry" action="dependents">Add dependent</a></p>
</fieldset>
</div>

<?php echo form_close();?>
</br />
<?php echo form_open('user/employment');?>
<div class="file201" id="employment">
<fieldset>
<legend>EMPLOYMENT HISTORY</legend>
<table border="1" cellspacing="0" cellpadding="5" id="employment_table" class="display">
	<thead>
		<tr>
			<th>Employer Name</th>
			<th>Position</th>
			<th>Date Started</th>
			<th>Date Ended</th>
			<th>Action</th>
		</tr>
	</thead>
<?php foreach($employment as $emp){
?>
<tr id="tr_employment_<?php echo $emp->id;?>">
<td><span name="employer_name"><?php echo isset($emp->employer_name)?$emp->employer_name:'';?></span></td>
<td><span name="position"><?php echo isset($emp->position)?$emp->position:'';?></span></td>
<td><span name="date_start"><?php echo isset($emp->date_start)?$emp->date_start:'';?></span></td>
<td><span name="date_end"><?php echo isset($emp->date_end)?$emp->date_end:'';?></span></td>

<td>
	<a href="javascript:;" onClick="editData('<?php echo $emp->id?>','employment')" >Edit</a> | <a href="javascript:;" onClick="deleteData('<?php echo $emp->id?>','employment')">Delete</a>
	</td>
</tr>
<?php } ?>
</table>
<p><a href="#" class="add_entry" action="employment">Add employment</a></p>
</fieldset>
</div>
<?php echo form_close();?>

<?php echo form_open('user/salary', array('target'=>'hidden_frame'));?>
<div class="file201" id="salary">
<?php 
if(isset($salary->info)){
	$monthly = $salary->info->monthly;
	$daily = $salary->info->daily;
}

?>
<fieldset>
<legend>SALARY</legend>
	<ul>
	<li>
		<div class="list_item">
		<ul>
			<li> 
			<label for="daily">Monthly</label>
			<input type="text" name="monthly" id="monthly" size="6" value="<?php echo isset($monthly)?CommonUtils::number_format($monthly,2):'0.00'?>" /> (PHP)</li>
			<li> 
			<label for="daily">Daily </label>
			<input type="text" name="daily" id="daily" size="6" value="<?php echo isset($daily)?CommonUtils::number_format($daily,2):'0.00'?>" /> (PHP)
			</li>
		</ul>
		</div>
	</li>
	<li>
	<?php echo form_hidden("user_id",$user_id);?>
	<input type="submit" name="submit" id="submit" value="Save"></li>
	</ul>
</fieldset>
</div>
<?php echo form_close();?>



<div class="file201" id="contributions">
<fieldset>
<legend>CONTRIBUTIONS/DEDUCTIONS</legend>
	<table width="100%">
		<tr>
			<td width="50%">
			<?php echo form_open('user/contributions', array('id'=>'contributions_form','method_name'=>'contributions'));?>
				<ul>
					<li>
						<div class="list_item">
						<ul>
							<li> 
							<label for="sss">SSS</label>
							<input type="text" name="sss" id="sss" size="6" value="<?php echo isset($contributions)?$contributions->sss->employee:"0.00"?>" /> monthly
							</li>
							
							<li> <label for="hdmf">HDMF</label>
							<input type="text" name="hdmf" id="hdmf" size="6" value="<?php echo isset($contributions)?$contributions->hdmf->employee:"0.00"?>" /> monthly</li>
							
							<li> <label for="philhealth">PhilHealth</label>
							<input type="text" name="philhealth" id="philhealth" size="6" value="<?php echo isset($contributions)?$contributions->philhealth->employee:"0.00"?>" /> monthly
							</li>
							<li> <label for="wtax">Witholding Tax</label>
							<input type="text" name="tax" id="tax" size="6" value="<?php echo isset($contributions)?$contributions->tax->employee:"0.00"?>" /> monthly
							</li>
							<li> <label for="sss_loan">SSS Loan</label>
							<input type="text" name="sss_loan" id="sss_loan" size="6" value="<?php echo isset($contributions)?$contributions->sss_loan->employee:"0.00"?>" /> monthly
							</li>
							<li> <label for="hdmf_loan">HDMF Loan</label>
							<input type="text" name="hdmf_loan" id="hdmf_loan" size="6" value="<?php echo isset($contributions)?$contributions->hdmf_loan->employee:"0.00"?>" /> monthly
							</li>
						</ul>
						</div>
					</li>
					<li><input type="submit" name="submit" id="submit" value="Save"></li>
				</ul>
				<?php echo form_hidden("user_id",$user_id);?>
			<?php echo form_close();?>
			</td>
			<td valign="top">
			<?php echo form_open('user/deductions', array('id'=>'deductions_form', 'method_name'=>'deductions'));?>
			<ul>
					<li>
						<div class="list_item">
						<ul>
							<li> 
							<label for="sss">Canteen</label>
							<input type="text" name="canteen" id="canteen" size="6" value="" />
							<input type="hidden" name="id" value="<?php echo isset($emp->id)?$emp->id:'';?>"></li>
							
							<li> <label for="hdmf">Clothing</label>
							<input type="text" name="clothing" id="clothing" size="6" value="" /></li>
							
							<li> <label for="philhealth">Cash Advance</label>
							<input type="text" name="cash_advance" id="cash_advance" size="6" value="" />
							</li>
							<li> <label for="wtax">Others</label>
							<input type="text" name="others" id="others" size="6" value="" />
							</li>
						</ul>
						</div>
					</li>
					<li><input type="submit" name="submit" id="submit" value="Save"></li>
				</ul>
				<?php echo form_hidden("user_id",$user_id);?>
				<?php echo form_close();?>
			</td>
		</tr>
	</table>
	
</fieldset>
</div>



</div>
<link rel="stylesheet" href="<?php echo base_url()?>css/ui/base/jquery.ui.all.css">
<script src="<?php echo base_url()?>js/jquery/jquery-ui/jquery.ui.core.js"></script>
<script src="<?php echo base_url()?>js/jquery/jquery-ui/jquery.ui.widget.js"></script>
<script src="<?php echo base_url()?>js/jquery/jquery-ui/jquery.ui.datepicker.js"></script>

<script language="javascript">
$(function() {
	$("#birth_date").datepicker();
	//$("#birth_date").formatDate('yy-mm-dd');
	$("#birth_date").datepicker( "option", "dateFormat", 'yy-mm-dd' );
	<?php if((int)($user[0]->birth_date) > 0 ):?>
	$("#birth_date").datepicker( "setDate" , "<?php echo $user[0]->birth_date?>" );
	<?php endif;?>
});
$(document).ready(function() {
	$('a#upload_link').click(function(){
		$('input[name="userfile"]').trigger('click');
	})
	$('input[name="userfile"]').change(function(){
		if($(this).val() != ''){
			$('input#upload_button').trigger('click');
			$('#image_preloader').show();
		}
		
	});

	$('div#image_preloader').hide();

	$('a.add_entry').click(function(){
		action = $(this).attr('action');
		url = '<?php echo base_url()?>user/' + action + "/<?php echo $user_id?>";
		//alert(url);
		$.fancybox.open({
			href : url,
			type : 'iframe',
			padding : 10,
			height: '70%',
			width: 600,
			autoSize	: false,
			helpers:  {
				overlay : {
					opacity  : 0.4,
					closeClick: false
				}
		    },
		    'afterClose': function(){document.location = document.location}
		});
	})

	$('.edit_delete').hide();
	$('.list_item').mouseover(function(){
		$(this).find('.edit_delete').show();
	}).mouseout(function(){	
		$(this).find('.edit_delete').hide();
	});


	$('#file201_form').submit(function(){
		setMessageOverlay("Updating your profile. Please wait.");
		loadOverlay();
		
		var postdata = $(this).serialize();
		$.post("<?php echo base_url()?>user/file201", postdata, function(data) {
			setMessageOverlay("Data successfully saved.");
			setTimeout("unloadOverlay()",800);
            //alert('Data saved!##');
        });
		return false;
	})

	$('#contributions_form, #deductions_form').submit(function(){
		//$("#overlay_box p.loading_message").html("Updating contributions. Please wait.");
		setMessageOverlay("Updating contributions. Please wait.");
		//$("#overlay_box").overlay().load();
		loadOverlay();
		var postdata = $(this).serialize();
		var method_name = $(this).attr('method_name');
		$.post("<?php echo base_url()?>user/" + method_name, postdata, function(data) {
			//$("#overlay_box p.loading_message").html(data);
			setMessageOverlay(data);
			setTimeout("unloadOverlay()",800);
            //alert(data);
        });
		return false;
	})
	
	$('#upload_button').submit(function(){
		$("#overlay_box p.loading_message").html("Uploading new photo. Please wait.");
		$("#overlay_box").overlay().load();
	})
	
	$('#dependents_table, #education_table, #employment_table').dataTable({
		"sPaginationType": "full_numbers",
		"iDisplayLength":25,
		"bSort": false,
		"bPaginate": false
	});
	$('#dependents_table_info, #education_table_info, #employment_table_info ').hide();
	$('#dependents_table_filter, #education_table_filter, #employment_table_filter').hide();

	
	
} );
function highlight(divId){
	//$(divId).find('.list_item').addClass('div_highlight').fadeIn('slow');
	$(divId).addClass('div_highlight').fadeIn('slow');
	setTimeout(function(){$(divId).find('.list_item').removeClass('div_highlight')},3000);
}

function editData(id,action){
	url = '<?php echo base_url()?>user/edit_' + action + "/<?php echo $user_id?>/" + id;
	$.fancybox.open({
		href : url,
		type : 'iframe',
		padding : 10,
		height: '70%',
		width: 600,
		autoSize	: false,
		helpers:  {
			overlay : {
				opacity  : 0.4,
				closeClick: false
			}
	    }
	});

}

function deleteData(id, tab){
	//tab = $(this).attr('label');
	var answer = confirm("Are you sure to delete this " + tab + "?");
	if(answer == true){
		action = $(this).attr('action');//'delete_dependent';
		//id = $(this).attr('itemid');
		//alert(depid);
		$.ajax({
		  url: '<?php echo base_url()?>user/delete_' + tab ,
		  type: "POST",
		  data:{user_id:'<?php echo $user_id?>', id:id},
		  success: function(data) {
		  	if(data=='success'){
			  	$('#tr_' + tab + '_' + id).remove()
				//alert(tab + " successfully deleted!");
		  	}
		  }
		});
		
	}
}



</script>
<iframe id="hidden_frame" name="hidden_frame"></iframe>
